package com.berwin.caper.view.components.filetree;

import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;

public class JFileNode extends DefaultMutableTreeNode {

    private File file = null;
    private boolean isDirectory = false;

    public JFileNode(File file) {
        super();
        this.file = file;
        this.setUserObject(this.file.getName());
        this.isDirectory = this.file.isDirectory();
    }

    public boolean isDirectory() {
        return this.isDirectory;
    }

    public void recursiveChildren() {

    }

    public String getName() {
        String path = this.file.getAbsolutePath();
        int idx = path.lastIndexOf(File.separator);
        if (idx <= -1)
            return "";
        return this.file.getAbsolutePath().substring(idx + 1, path.length());
    }


    public File getFile() {
        return this.file;
    }

    public String getFilePath() {
        return this.file.getAbsolutePath();
    }
}
